window: Add hide-titlebar-when-maximized property
authorFlorian Müllner <fmuellner@gnome.org>
Sat, 3 Dec 2011 00:47:25 +0000 (01:47 +0100)
committerFlorian Müllner <fmuellner@gnome.org>
Thu, 15 Dec 2011 15:31:56 +0000 (16:31 +0100)
For maximized windows, titlebars cannot be used to reposition or
scale the window, so if an application does not use it to convey
useful information (other than the application name), the screen
space occupied by titlebars could be put to better use.
Add a new window property which requests from the window manager
to hide titlebars when windows are maximized to account for this.

https://bugzilla.gnome.org/show_bug.cgi?id=665616

docs/reference/gdk/gdk3-sections.txt
docs/reference/gtk/gtk3-sections.txt
gdk/x11/gdkwindow-x11.c
gdk/x11/gdkx11window.h
gtk/gtkwindow.c
gtk/gtkwindow.h

index e88b86538eebbe79147aeb3da11509e9e870737e..b75df8bb3fdb204a016f3244c73f249f604fe040 100644 (file)
@@ -959,6 +959,7 @@ gdk_x11_screen_supports_net_wm_hint
 gdk_x11_window_foreign_new_for_display
 gdk_x11_window_lookup_for_display
 gdk_x11_window_get_xid
+gdk_x11_window_set_hide_titlebar_when_maximized
 gdk_x11_window_set_theme_variant
 gdk_x11_window_set_user_time
 gdk_x11_window_move_to_current_desktop
index 4c3c8c03410373ff4078827c53632a5aa0a48680..14d81bca42ef7762070d0af59913521dc2ccae86 100644 (file)
@@ -5291,6 +5291,7 @@ gtk_window_get_gravity
 gtk_window_set_position
 gtk_window_set_transient_for
 gtk_window_set_destroy_with_parent
+gtk_window_set_hide_titlebar_when_maximized
 gtk_window_set_screen
 gtk_window_get_screen
 gtk_window_is_active
@@ -5336,6 +5337,7 @@ gtk_window_get_default_icon_list
 gtk_window_get_default_icon_name
 gtk_window_get_default_size
 gtk_window_get_destroy_with_parent
+gtk_window_get_hide_titlebar_when_maximized
 gtk_window_get_icon
 gtk_window_get_icon_list
 gtk_window_get_icon_name
index d48927fc7d7cda011f1161b6b3056842245ea8d4..688655f0e891b9dcd4ccca5a9ccaadcd4c553a84 100644 (file)
@@ -3130,6 +3130,49 @@ gdk_x11_window_set_theme_variant (GdkWindow *window,
     }
 }
 
+/**
+ * gdk_x11_window_set_hide_titlebar_when_maximized:
+ * @window: (type GdkX11Window): a #GdkWindow
+ * @hide_titlebar_when_maximized: whether to hide the titlebar when
+ *                                maximized
+ *
+ * Set a hint for the window manager, requesting that the titlebar
+ * should be hidden when the window is maximized.
+ *
+ * Note that this property is automatically updated by GTK+, so this
+ * function should only be used by applications which do not use GTK+
+ * to create toplevel windows.
+ *
+ * Since: 3.4
+ */
+void
+gdk_x11_window_set_hide_titlebar_when_maximized (GdkWindow *window,
+                                                 gboolean   hide_titlebar_when_maximized)
+{
+  GdkDisplay *display;
+
+  if (!WINDOW_IS_TOPLEVEL (window))
+    return;
+
+  display = gdk_window_get_display (window);
+
+  if (hide_titlebar_when_maximized)
+    {
+      guint32 hide = 1;
+      XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
+                       GDK_WINDOW_XID (window),
+                       gdk_x11_get_xatom_by_name_for_display (display, "_GTK_HIDE_TITLEBAR_WHEN_MAXIMIZED"),
+                       XA_CARDINAL, 32,
+                       PropModeReplace, (guchar *)&hide, 1);
+    }
+  else
+    {
+      XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
+                       GDK_WINDOW_XID (window),
+                       gdk_x11_get_xatom_by_name_for_display (display, "_GTK_HIDE_TITLEBAR_WHEN_MAXIMIZED"));
+    }
+}
+
 #define GDK_SELECTION_MAX_SIZE(display)                                 \
   MIN(262144,                                                           \
       XExtendedMaxRequestSize (GDK_DISPLAY_XDISPLAY (display)) == 0     \
index 1e8a09ad34c3b35feacd6be8d783a4dc129e026d..f648d965acc3a4cc05cd858785afa9b29f050fdb 100644 (file)
@@ -59,6 +59,8 @@ void     gdk_x11_window_set_user_time     (GdkWindow   *window,
                                            guint32      timestamp);
 void     gdk_x11_window_set_theme_variant (GdkWindow   *window,
                                            char        *variant);
+void     gdk_x11_window_set_hide_titlebar_when_maximized (GdkWindow *window,
+                                                          gboolean   hide_titlebar_when_maximized);
 void     gdk_x11_window_move_to_current_desktop (GdkWindow   *window);
 
 /**
index fd23dd9a71d0cee5fed875d2c99adf7ce54f3814..a07da04c40e0fba19fa3faea2d443af86920dbe6 100644 (file)
@@ -152,6 +152,7 @@ struct _GtkWindowPrivate
   guint    has_focus                 : 1;
   guint    has_user_ref_count        : 1;
   guint    has_toplevel_focus        : 1;
+  guint    hide_titlebar_when_maximized : 1;
   guint    iconify_initially         : 1; /* gtk_window_iconify() called before realization */
   guint    is_active                 : 1;
   guint    maximize_initially        : 1;
@@ -206,6 +207,7 @@ enum {
   PROP_DEFAULT_WIDTH,
   PROP_DEFAULT_HEIGHT,
   PROP_DESTROY_WITH_PARENT,
+  PROP_HIDE_TITLEBAR_WHEN_MAXIMIZED,
   PROP_ICON,
   PROP_ICON_NAME,
   PROP_SCREEN,
@@ -699,6 +701,21 @@ gtk_window_class_init (GtkWindowClass *klass)
                                                          FALSE,
                                                         GTK_PARAM_READWRITE));
 
+  /**
+   * GtkWindow:hide-titlebar-when-maximized:
+   *
+   * Whether the titlebar should be hidden during maximization.
+   *
+   * Since: 3.4
+   */
+  g_object_class_install_property (gobject_class,
+                                   PROP_HIDE_TITLEBAR_WHEN_MAXIMIZED,
+                                   g_param_spec_boolean ("hide-titlebar-when-maximized",
+                                                        P_("Hide the titlebar during maximization"),
+                                                        P_("If this window's titlebar should be hidden when the window is maximized"),
+                                                         FALSE,
+                                                        GTK_PARAM_READWRITE));
+
   g_object_class_install_property (gobject_class,
                                    PROP_ICON,
                                    g_param_spec_object ("icon",
@@ -1209,6 +1226,9 @@ gtk_window_set_property (GObject      *object,
     case PROP_DESTROY_WITH_PARENT:
       gtk_window_set_destroy_with_parent (window, g_value_get_boolean (value));
       break;
+    case PROP_HIDE_TITLEBAR_WHEN_MAXIMIZED:
+      gtk_window_set_hide_titlebar_when_maximized (window, g_value_get_boolean (value));
+      break;
     case PROP_ICON:
       gtk_window_set_icon (window,
                            g_value_get_object (value));
@@ -1323,6 +1343,9 @@ gtk_window_get_property (GObject      *object,
     case PROP_DESTROY_WITH_PARENT:
       g_value_set_boolean (value, priv->destroy_with_parent);
       break;
+    case PROP_HIDE_TITLEBAR_WHEN_MAXIMIZED:
+      g_value_set_boolean (value, priv->hide_titlebar_when_maximized);
+      break;
     case PROP_ICON:
       g_value_set_object (value, gtk_window_get_icon (window));
       break;
@@ -3039,6 +3062,61 @@ gtk_window_get_destroy_with_parent (GtkWindow *window)
   return window->priv->destroy_with_parent;
 }
 
+/**
+ * gtk_window_set_hide_titlebar_when_maximized:
+ * @window: a #GtkWindow
+ * @setting: whether to hide the titlebar when @window is maximized
+ *
+ * If @setting is %TRUE, then @window will request that it's titlebar
+ * should be hidden when maximized.
+ * This is useful for windows that don't convey any information other
+ * than the application name in the titlebar, to put the available
+ * screen space to better use. If the underlying window system does not
+ * support the request, the setting will not have any effect.
+ *
+ * Since: 3.4
+ **/
+void
+gtk_window_set_hide_titlebar_when_maximized (GtkWindow *window,
+                                             gboolean   setting)
+{
+  g_return_if_fail (GTK_IS_WINDOW (window));
+
+#ifdef GDK_WINDOWING_X11
+  {
+    GdkWindow *gdk_window;
+
+    gdk_window = gtk_widget_get_window (GTK_WIDGET (window));
+
+    if (GDK_IS_X11_WINDOW (gdk_window))
+      gdk_x11_window_set_hide_titlebar_when_maximized (gdk_window, setting);
+  }
+#endif
+
+  window->priv->hide_titlebar_when_maximized = setting;
+  g_object_notify (G_OBJECT (window), "hide-titlebar-when-maximized");
+}
+
+/**
+ * gtk_window_get_hide_titlebar_when_maximized:
+ * @window: a #GtkWindow
+ *
+ * Returns whether the window has requested to have its titlebar hidden
+ * when maximized. See gtk_window_set_hide_titlebar_when_maximized ().
+ *
+ * Return value: %TRUE if the window has requested to have its titlebar
+ *               hidden when maximized
+ *
+ * Since: 3.4
+ **/
+gboolean
+gtk_window_get_hide_titlebar_when_maximized (GtkWindow *window)
+{
+  g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
+
+  return window->priv->hide_titlebar_when_maximized;
+}
+
 static GtkWindowGeometryInfo*
 gtk_window_get_geometry_info (GtkWindow *window,
                              gboolean   create)
@@ -4760,7 +4838,11 @@ gtk_window_map (GtkWidget *widget)
   gdk_window_set_keep_below (gdk_window, priv->below_initially);
 
   if (priv->type == GTK_WINDOW_TOPLEVEL)
-    gtk_window_set_theme_variant (window);
+    {
+      gtk_window_set_theme_variant (window);
+      gtk_window_set_hide_titlebar_when_maximized (window,
+                                                   priv->hide_titlebar_when_maximized);
+    }
 
   /* No longer use the default settings */
   priv->need_default_size = FALSE;
index d44eedaf7d0e327eb93f047bb95a0879677ad2fe..17203070e220522afdc9dafe9a6b9a12bf3a786d 100644 (file)
@@ -159,6 +159,9 @@ gboolean   gtk_window_get_focus_on_map         (GtkWindow           *window);
 void       gtk_window_set_destroy_with_parent  (GtkWindow           *window,
                                                 gboolean             setting);
 gboolean   gtk_window_get_destroy_with_parent  (GtkWindow           *window);
+void       gtk_window_set_hide_titlebar_when_maximized (GtkWindow   *window,
+                                                        gboolean     setting);
+gboolean   gtk_window_get_hide_titlebar_when_maximized (GtkWindow   *window);
 void       gtk_window_set_mnemonics_visible    (GtkWindow           *window,
                                                 gboolean             setting);
 gboolean   gtk_window_get_mnemonics_visible    (GtkWindow           *window);